using System;
using System.Collections;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;

using WHC.Pager.Entity;
using Microsoft.Practices.EnterpriseLibrary.Data;
using WHC.Hotel.Entity;
using WHC.Hotel.IDAL;
using WHC.OrderWater.Commons;

namespace WHC.Hotel.DAL
{
    /// <summary>
    /// TeaGoodsDiscount 的摘要说明。
    /// </summary>
    public class TeaGoodsDiscount : BaseDAL<TeaGoodsDiscountInfo>, ITeaGoodsDiscount
    {
        #region 对象实例及构造函数

        public static TeaGoodsDiscount Instance
        {
            get
            {
                return new TeaGoodsDiscount();
            }
        }
        public TeaGoodsDiscount()
            : base("CL_TeaGoodsDiscount", "ID")
        {
        }

        #endregion

        /// <summary>
        /// 将DataReader的属性值转化为实体类的属性值，返回实体类
        /// </summary>
        /// <param name="dr">有效的DataReader对象</param>
        /// <returns>实体类对象</returns>
        protected override TeaGoodsDiscountInfo DataReaderToEntity(IDataReader dataReader)
        {
            TeaGoodsDiscountInfo teaGoodsDiscountInfo = new TeaGoodsDiscountInfo();
            SmartDataReader reader = new SmartDataReader(dataReader);

            teaGoodsDiscountInfo.ID = reader.GetInt32("ID");
            teaGoodsDiscountInfo.Goods_ID = reader.GetInt32("Goods_ID");
            teaGoodsDiscountInfo.Price = reader.GetDecimal("Price");
            teaGoodsDiscountInfo.CustomerGrade = reader.GetString("CustomerGrade");
            teaGoodsDiscountInfo.DiscountRate = reader.GetDouble("DiscountRate");
            teaGoodsDiscountInfo.DiscountPrice = reader.GetDecimal("DiscountPrice");

            return teaGoodsDiscountInfo;
        }

        /// <summary>
        /// 将实体对象的属性值转化为Hashtable对应的键值
        /// </summary>
        /// <param name="obj">有效的实体对象</param>
        /// <returns>包含键值映射的Hashtable</returns>
        protected override Hashtable GetHashByEntity(TeaGoodsDiscountInfo obj)
        {
            TeaGoodsDiscountInfo info = obj as TeaGoodsDiscountInfo;
            Hashtable hash = new Hashtable();

            hash.Add("Goods_ID", info.Goods_ID);
            hash.Add("Price", info.Price);
            hash.Add("CustomerGrade", info.CustomerGrade);
            hash.Add("DiscountRate", info.DiscountRate);
            hash.Add("DiscountPrice", info.DiscountPrice);

            return hash;
        }


        public List<TeaGoodsDiscountInfo> GetDiscount(int goodsID)
        {
            string condition = string.Format("Goods_ID ={0} ", goodsID);
            return Find(condition);
        }
    }
}